package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.VisitorsRecord;
import cn.bgs.service.IVisitorsRecordService;
import cn.bgs.vo.CellIntermediate;
import cn.bgs.vo.VisitorsrecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 访客记录表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/visitors-record")
public class VisitorsRecordController {

    @Autowired
    private IVisitorsRecordService iVisitorsRecordService;

    /**
     * 添加访客信息
     * @param cellIntermediate
     * @return
     */
    @PostMapping("/insertvisitorsrecord")
    public R insertvisitorsrecord(@RequestBody CellIntermediate cellIntermediate){
        int i=iVisitorsRecordService.insertvisitorsrecord(cellIntermediate);
        if(i>0){
            return R.ok().code(2000);
        }
     return R.ok().data("error","失败");
    }

    /**
     * 访客记录
     * @param id
     * @return
     */
    @GetMapping("/getVisitorsList")
    public R getVisitorsList(@RequestParam("id") Integer id,@RequestParam("datetime") String datetime){
        System.out.println(datetime);
        String[] arr= datetime.split(",");
        if (arr.length==2){
            String stratTime=arr[0];
            System.out.println(stratTime);
            String endTime=arr[1];
            System.out.println(endTime);
            List<VisitorsrecordVo> list= iVisitorsRecordService.getVisitorsList(id,stratTime,endTime);
            return R.ok().data("list",list);
        }
        String stratTime="";
        String endTime="";
        List<VisitorsrecordVo> list= iVisitorsRecordService.getVisitorsList(id,stratTime,endTime);
        return R.ok().data("list",list);
    }
}
